package com.forum.controller.admin;

import com.forum.constant.MessageConstant;
import com.forum.dto.NoticeDTO;
import com.forum.entity.Notifications;
import com.forum.result.Result;
import com.forum.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "通知")
@RestController
@RequestMapping("/admin/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @ApiOperation("通知查询")
    @GetMapping("/query")
    public Result<Notifications> query() {
        return Result.success(noticeService.query());
    }

    @ApiOperation("发布通知")
    @PostMapping("/publish")
    public Result publish(NoticeDTO noticeDTO) {
        noticeService.publish(noticeDTO);
        return Result.success(MessageConstant.INSERT_SUCCESS);
    }

    @ApiOperation("删除通知")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids) {
        noticeService.deleteById(ids);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }

    @ApiOperation("修改通知")
    @PutMapping
    public Result update(NoticeDTO noticeDTO) {
        noticeService.updateById(noticeDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }
}
